﻿using System;
using System.Text;
using System.Collections.Generic;
using Gencode.Common.SQL;
using System.Data;
using System.Windows.Forms;

namespace Personalplaner.AppData
{
	class ComboDataGenerator
	{
		/// <summary>
		/// Fills the given Combobox with all Anstellungen
		/// </summary>
		/// <param name="combo">Reference of the Combobox to be filled</param>
		/// <returns>The DataView of the Combobox</returns>
		public static DataView FillComboAnstellungen(ref ComboBox combo, string mandid)
		{
			DataView dv = SimpleQuerry.ExecuteForDataView("select AnstellungID, Name from Anstellung where mandid = '" + mandid + "' order by Prioritaet");

			if (dv != null && dv.Count > 0)
			{
				combo.DataSource = dv;
				combo.DisplayMember = "name";
			}

			return dv;
		}

		/// <summary>
		/// Fills the given Combobox with all open Years
		/// </summary>
		/// <param name="combo">Reference of the Combobox to be filled</param>
		/// <returns>The DataView of the Combobox</returns>
		public static DataView FillComboOpenYears(ref ComboBox combo)
		{
			DataView dv = SimpleQuerry.ExecuteForDataView("select Jahr, JahrID from PlanungsJahr");

			if (dv != null && dv.Count > 0)
			{
				combo.DataSource = dv;
				combo.DisplayMember = "Jahr";
			}

			return dv;
		}

        /// <summary>
        /// Fills the given Combobox with Schemanames
        /// </summary>
        /// <param name="combo">Reference of the Combobox to be filled</param>
        /// <param name="all">Gets only active schemas if false. Gets all schemas if true</param>
        /// <returns>The DataView of the Combobox</returns>
        public static DataView FillComboSchemas(ref ComboBox combo, bool all)
        {
            string sqlString = string.Empty;
            if(all)
                sqlString = "select SchemaID, Name from Schemas";
            else
                sqlString = "select SchemaID, Name from Schemas where Status = 1";

            DataView dv = SimpleQuerry.ExecuteForDataView(sqlString);
            if (dv != null && dv.Count > 0)
            {
                combo.DataSource = dv;
                combo.DisplayMember = "Name";
            }

            return dv;
        }
	}
}
